<?php
namespace Admin\Controller;
use Think\Controller;
class SystemController extends CommonController {
    public function index(){
        $this->basic();
    }
    public function basic(){
        $basic_object = D('basic_config');
        if (IS_POST) {
            $data = $basic_object->create();
            if ($data) {
                $rs = $basic_object->save($data);
                if ($rs) {
                    $ajax = array(
                      'status'=>1,
                      'text'=>'基本设置保存成功',
                      'url'=>U('basic')
                    );
                } else {
                    $ajax = array(
                      'status'=>0,
                      'text'=>'基本设置保存失败',
                      'url'=>''
                    );
                }
            }else {
                $ajax = array(
                  'status'=>0,
                  'text'=>$basic_object->getError(),
                  'url'=>''
                );
            }
            $this->ajaxReturn($ajax);
        }else {
            $this->assign('mark','system');
            $this->assign('umark','basic');

            $form_data = $basic_object->find(1);

            A('form')->setMetaTitle('基本设置')
            ->setBreadCrumb(array('系统','系统设置','基本设置'))
            ->setPostUrl(U('basic'))
            ->addFormItem('id','hidden')
            ->addFormItem('isenabled','switch','网站开关','站点关闭后将不能访问，后台可正常登录',array('开启','关闭'))
            ->addFormItem('title','text','网站标题','',array(),array('required'=>true))
            ->addFormItem('logo','image','网站LOGO','')
            ->addFormItem('desc','text','网站描述','')
            ->addFormItem('keywords','textarea','网站关键字','')
            ->addFormItem('tel','text','联系电话','')
            ->addFormItem('email','text','联系邮箱','')
            ->addFormItem('copyright','text','底部版权','')
            ->addFormItem('recard','text','备案号','')
            ->addFormItem('statistics','textarea','站点统计代码','')
            ->setFormData($form_data)
            ->fetch();
        }
    }

    public function system(){
        $system_object = D('system_config');
        if (IS_POST) {
            $data = $system_object->create();
            if ($data) {
                $rs = $system_object->save($data);
                if ($rs) {
                    $ajax = array(
                      'status'=>1,
                      'text'=>'后台设置保存成功',
                      'url'=>U('system')
                    );
                } else {
                    $ajax = array(
                      'status'=>0,
                      'text'=>'后台设置保存失败',
                      'url'=>''
                    );
                }
            }else {
                $ajax = array(
                  'status'=>0,
                  'text'=>$system_object->getError(),
                  'url'=>''
                );
            }
            $this->ajaxReturn($ajax);
        }else {
            $this->assign('mark','system');
            $this->assign('umark','system');

            $form_data = $system_object->find(1);

            A('form')->setMetaTitle('后台设置')
            ->setBreadCrumb(array('系统','系统设置','后台设置'))
            ->setPostUrl(U('system'))
            ->addFormItem('id','hidden')
            ->addFormItem('file_upsize','text','文件上传大小限制','0为不限制大小，单位：kb')
            ->addFormItem('img_upsize','text','图片上传大小限制','0为不限制大小，单位：kb')
            ->addFormItem('page_size','text','分页数量','后台表格每页的记录数')
            ->setFormData($form_data)
            ->fetch();
        }
    }
}
